package com.example.testproject.domain;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

//动态代理-定义一个类实现InvocationHandler接口实现invoke方法
public class DongTai implements InvocationHandler {

    private Object object;
    //动态代理-代理对象是未知的，因此传递的参数应该所有类的父类Object类型
    public DongTai(Object object){
       this.object = object;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        Object result = method.invoke(object, args);    //调用真正的面包机做面包

        System.out.println("adding apricot...");        //方法增强
        return result;
    }
}
